home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 1 / Gold Medal Software Volume 1 (Gold Medal) (1994).iso / prog / tpwprog3.arj / UGLOBALS.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-07-02  |  9.6 KB  |  285 lines

  1. {******************************************************************}
  2. {                                                                  }
  3. {     Mancala                                                      }
  4. {     Turbo Pascal for Windows                                     }
  5. {     Copyright (c) 1991 by Swan Software. All rights reserved.    }
  6. {                                                                  }
  7. {******************************************************************}
  8.  
  9. { uglobals.pas -- Global declarations for Mancala }
  10.  
  11. unit Uglobals;
  12.  
  13. interface
  14.  
  15. uses WinTypes, WinProcs, Idents;
  16.  
  17. const
  18.  
  19.   app_Name = 'Mancala';   { Application name and window title }
  20.  
  21.  
  22. {- Search procedure in usearch uses search level to know which
  23. side is moving. Even values represent human moves; odd values
  24. represent computer moves. The following constants are for calling
  25. procedures also called by search when a level variable is not
  26. available (makemove for example) }
  27.  
  28.   human = 0;                      { Even value = human move }
  29.   computer = 1;                   { Odd value = computer move }
  30.  
  31.  
  32. {- The maxstack constant controls the total number of moves that
  33. can be maintained at one time. See also variables movestack and
  34. moveindex. Empirical tests indicate that 250 should be more than
  35. enough room to handle a search ply level of 7 (possibly 8). }
  36.  
  37.   maxStack = 250;                 { Maximum size of moverec stack }
  38.  
  39.  
  40. {- Maximum look-ahead. Should be odd so that computer searches its
  41. own moves on the deepest level. }
  42.  
  43.   maxSearchDepth = 7;
  44.  
  45.  
  46. {- Other variables, mostly self explanatory. }
  47.  
  48.   maxCups = 14;                   { 6 cups + 1 kalah per player }
  49.   maxCupIndex = MAXCUPS - 1;      { Used in FOR loops, etc. }
  50.   defaultPebbles = 3;             { Starting number of pebbles per cup }
  51.   maxPebbles = 9;                 { Maximum pebbles per cup allowed }
  52.  
  53.  
  54. {- Context-sensitive help "context" identifiers }
  55.  
  56.   hc_menu_game = 100;
  57.   hc_command_new = 105;
  58.   hc_command_exit = 110;
  59.   hc_menu_edit = 115;
  60.   hc_command_options = 120;
  61.   hc_command_level = 125;
  62.   hc_menu_action = 130;
  63.   hc_command_replay = 135;
  64.   hc_command_pass = 140;
  65.   hc_command_switch = 145;
  66.   hc_menu_help = 150;
  67.   hc_command_index = 155;
  68.   hc_command_using_help = 160;
  69.   hc_command_about = 165;
  70.  
  71.  
  72. type
  73.  
  74.  
  75. {- The CupIndex is the range of indexes allowed into the game
  76. board. This type is specific to Mancala only. Other games using the
  77. search engine do not need this. }
  78.  
  79.   CupIndex = 0 .. maxCupIndex;
  80.  
  81.  
  82. {- The game board in Mancala is a simple array of integers
  83. representing the number of pebbles in each cup. When designing a new
  84. game, you must create a Board data type, which can be any structure
  85. you want, a record, an array, or whatever you need. }
  86.  
  87.   Board = array[CupIndex] of Integer;
  88.  
  89.  
  90. {- Type OneMove defines the nature of a single move. In this
  91. game, a move is simply the cup index number. Another game could
  92. define OneMove as a string, or a coordinate on an 8x8 board, or a
  93. record containing a from position, a to position, and maybe flags to
  94. represent captures, and so on. In any case, you must define what
  95. OneMove is. }
  96.  
  97.   OneMove = CupIndex;
  98.  
  99.  
  100. {- Stack indexes locate positions in the MoveStack and BoardStack
  101. arrays. The indexes may be zero, in which case the arrays are
  102. empty. The stack range type defines the size of the MoveStack and
  103. BoardStack arrays. }
  104.  
  105.   StackIndex = 0 .. maxStack;
  106.   StackRange = 1 .. maxStack;
  107.  
  108.  
  109. {- A MoveRec contains one move and a score value representing the
  110. board evaluation (from the computer's point of view). The BoardIndex
  111. indexes the BoardStack array, locating the Gameboard after making
  112. this move, plus other details such as the Win flag. }
  113.  
  114.   MoveRec = record
  115.     Move: OneMove;              { The move }
  116.     Score: Integer;             { The evaluation score }
  117.     BoardIndex: StackRange;     { The gameboard after moving }
  118.   end;
  119.  
  120.  
  121. {- A ListRec contains an index to the first move of a list of
  122. moves for a certain Gameboard position, plus the count of moves on
  123. that list. These moves are stacked in the Movestack. This record is
  124. returned by MoveGen. A zero count indicates no legal moves for the
  125. player. In that case, field indexes are meaningless. }
  126.  
  127.   Listrec = record
  128.     FirstIndex: StackRange;     { First move on MoveStack }
  129.     LastIndex: StackRange;      { Last move on MoveStack }
  130.     Count: Integer;             { Number of moves on list }
  131.   end;
  132.  
  133.  
  134. {- A BoardRec stores various game facts to make it easy to create
  135. multiple playing boards during move searches. }
  136.  
  137.   Boardrec = record
  138.     GameBoard: Board;           { The current position }
  139.     GoAgain: Boolean;           { True if player goes again }
  140.     Win: Boolean;               { True if either side wins }
  141.     WinningSide: Integer        { Valid if Win is true }
  142.   end;
  143.  
  144.  
  145. var
  146.  
  147.   Side: Integer;                  { Side to move }
  148.   SelfPlay: Boolean;              { True for auto play }
  149.   CurrentMessage: Integer;        { Current message index }
  150.   XMax, YMax: Integer;            { Maximum display dimensions }
  151.   XCenter, YCenter: Integer;      { Display center coordinate }
  152.   XBase, YBase: Integer;          { Gameboard base coordinate }
  153.   CBackground: TColorRef;         { Color of window background }
  154.   COuterCup: TColorRef;           { Color of outer cup }
  155.   CPen: TColorRef;                { Color of pen (outlines) }
  156.   CInnerShadow: TColorRef;        { Color of inner shadow }
  157.   HumanMove: Integer;             { -1 = none; >= 0 = selected cup number }
  158.  
  159.  
  160. {- Indexes to computer's and human's kalah (home) and playing
  161. cups. The game is designed to use any number of cups, but the text
  162. interface is fixed to 6 cups per player. So, unless you change the
  163. interface, don't try to change the initial assignments to these
  164. variables. }
  165.  
  166.   CompKalah: CupIndex;            { Index to computer's kalah }
  167.   CompFirstCup: CupIndex;         { Index to computer's first cup }
  168.   CompLastCup: CupIndex;          { Index to computer's last cup }
  169.   HumanKalah: CupIndex;           { Index to human's kalah }
  170.   HumanFirstCup: CupIndex;        { Index to human's first cup }
  171.   HumanLastCup: CupIndex;         { Index to human's last cup }
  172.  
  173.  
  174. {- The number of pebbles per cup may be set to any value, but large
  175. numbers will cause best-move searches to take a very long time. The
  176. PebblesDiv2 value equals the number of pebbles required to win. Ties
  177. are not possible. }
  178.  
  179.   PebblesPerCup: Integer;         { Number of pebbles per cup }
  180.   PebblesDiv2: Integer;           { Number of pebbles needed to win }
  181.  
  182.  
  183. {- The BestMove is the result of calling Search. As long as you
  184. call search with at least one move for the current gameboard,
  185. BestMove will hold the computer's choice of moves for any search
  186. depth. }
  187.  
  188.   BestMove: OneMove;
  189.  
  190.  
  191. {- LowLevel is the starting search level. Search uses this
  192. variable to know when to assign the best move on a level to the
  193. global BestMove variable. }
  194.  
  195.   LowLevel: Integer;
  196.  
  197.  
  198. {- Set MaxPly to any value from 1 to maxSearchDepth before calling
  199. Search, which will examine that many levels plus one or two in the
  200. case of GoAhead moves (those where the player continues the turn).
  201. You may change MaxPly at any time during a game--it does not have to
  202. remain fixed for every move. Set MaxPly to an odd value to evaluate
  203. computer positions on the deepest level, or make it even to evaluate
  204. human responses on that level. }
  205.  
  206.   MaxPly: 1 .. maxSearchDepth;
  207.  
  208.  
  209. {- The MoveList stack contains lists of moves for a certain
  210. Gameboard position. Procedure MoveGen creates the move list, storing
  211. each move record on the stack. The MoveIndex points to the current
  212. top of the stack, which always contains a move record unless the
  213. stack is empty (MoveIndex=0). }
  214.  
  215.   MoveIndex: StackIndex;
  216.   MoveStack: array[StackRange] of MoveRec;
  217.  
  218.  
  219. {- The BoardStack holds a copy of the Gameboard after making each
  220. move on the MoveList. Move records on the MoveStack contain the
  221. field BoardIndex, which locates a game board copy in this array.
  222. MoveIndex serves as the BoardStack stack pointer. }
  223.  
  224.   BoardStack: array[StackRange] of BoardRec;
  225.  
  226.  
  227. {- The MainPosition is the board on which all moves are made. }
  228.  
  229.   MainPosition: BoardRec;
  230.  
  231.  
  232. {- The cupcoords array stores the anchor coordinate for each displayed
  233. cup on the gameboard. All references to the cup, mouse clicks, pebble
  234. animations, etc., are made by passing an index referring to this array. }
  235.  
  236.   CupCoords: array[CupIndex] of TPoint;
  237.  
  238.  
  239. {- Instant-replay information }
  240.  
  241.   ReplayOk: Boolean;
  242.   ReplayBoard: BoardRec;
  243.   ReplayMove: OneMove;
  244.   ReplaySide: Integer;
  245.  
  246.  
  247. {- Bitmap handle for flashing cup to show computer's move }
  248.  
  249.   FlashBits: HBitmap;
  250.  
  251.  
  252. implementation
  253.  
  254.  
  255. {- Perform various initializations for this unit }
  256.  
  257. begin
  258.   CurrentMessage := 1;
  259.   CBackground := RGB(255, 255, 255);
  260.   COuterCup := RGB(192, 31, 51);
  261.   CPen := RGB(0, 0, 0);
  262.   CInnerShadow := RGB(64, 64, 0);
  263.   CompKalah := 0;
  264.   HumanKalah := maxCups div 2;
  265.   PebblesPerCup := DefaultPebbles;
  266.   CompFirstCup := HumanKalah + 1;
  267.   CompLastCup := MaxCupIndex;
  268.   HumanFirstCup := 1;
  269.   HumanLastCup := HumanKalah - 1;
  270.   MaxPly := maxSearchDepth;
  271.   XMax := 524;
  272.   YMax := 360 + GetSystemMetrics(sm_CYMenu);
  273.   XCenter := GetSystemMetrics(sm_CXScreen) div 2;
  274.   YCenter := GetSystemMetrics(sm_CYScreen) div 2;
  275.   XBase := (XMax - 472) div 2;
  276.   YBase := (YMax div 2) - 64;
  277.   HumanMove := -1;
  278. end.
  279.  
  280.  
  281. { ----------------------------------------------------------------
  282.   Copyright (c) 1991 by Swan Software. All rights reserved.
  283.   Revision 1.00    Date: 8/21/1991
  284.   ---------------------------------------------------------------- }
  285.